package edu.upc.galaxy.dao;

import edu.upc.galaxy.entity.LocalENTITY;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alvaro
 */
public class LocalDAO extends BaseDAO {

    
    public Integer insertar(LocalENTITY local) {
        String insert = "insert into local(nombre,direccion) values (?,?)";
        List list = new ArrayList();
        list.add(local.getNombre());
        list.add(local.getDireccion());
        return this.insert(insert, list);
    }
    
    public void actualizar(LocalENTITY local) {
        String update = "update local set nombre = ?, direccion = ? where id = ?";
        List list = new ArrayList();
        list.add(local.getNombre());
        list.add(local.getDireccion());
        list.add(local.getCodlocal());
        this.update(update, list);
    }
    
    public void eliminar(LocalENTITY local) {
        String delete = "delete from local where id = ?";
        this.delete(delete,local.getCodlocal());
    }
    
    public List<LocalENTITY> buscar() {
        ResultSet rs = this.select("select * from local");
        List<LocalENTITY> listado = new ArrayList<LocalENTITY>();
        try {
            while (rs.next()) {
                LocalENTITY local = new LocalENTITY();
                local.setCodlocal(rs.getInt(1));
                local.setNombre(rs.getString(2));
                local.setDireccion(rs.getString(3));
                listado.add(local);
            }
        } catch (SQLException ex) {
            Logger.getLogger(LocalDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return listado;
    }  
}
